package com.malty.rocketmq.consumer;

import com.malty.rocketmq.constant.MqTopicConst;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author malty
 */
@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = "test", topic = MqTopicConst.JAVA_CLIENT_TEST, messageModel = MessageModel.CLUSTERING)
public class Consumer implements RocketMQListener<String> {
    @SneakyThrows
    @Override
    public void onMessage(String message) {
        Long start = null;
        if (message.contains("_")) {
            String[] split = message.split("_");
            start = System.currentTimeMillis() - Long.parseLong(split[1]);
        }
//        Thread.sleep(2000);
        log.info("监听到消息，message：{}, delay time:{}", message, start);
    }
}
